package com.example.yuejianapp14.Activity.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yuejianapp14.Activity.Activity.CoachActivity;
import com.example.yuejianapp14.Activity.JavaBean.Coach;
import com.example.yuejianapp14.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by jason_lin on 2017/10/13.
 */

public class ClubInfoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Coach> mDataList;
    private LayoutInflater mLayoutInflater;

    public ClubInfoAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflater.from(parent.getContext()).inflate(R.layout.coachcard,parent,false);
        return new ClubInfoAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Coach entity = (Coach) mDataList.get(position);
        if (null == entity)
            return;
        ClubInfoAdapter.ViewHolder viewHolder = (ClubInfoAdapter.ViewHolder) holder;
        viewHolder.coach_name.setText(entity.getCoachname());
        viewHolder.coach_info.setText(entity.getCoachinstruction());


        Picasso.with(mContext).load("http://10.0.2.2/YueJian/Public/photo/coachphoto/"+entity.getCoachpic()).into(viewHolder.coach_pic);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,CoachActivity.class);
                intent.putExtra("coachid",entity.getCoachid());
                intent.putExtra("coachpic",entity.getCoachpic());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView coach_pic;
        TextView coach_name;
        TextView coach_info;
        LinearLayout coach_container;

        public ViewHolder(View itemView) {
            super(itemView);
            coach_name = (TextView) itemView.findViewById(R.id.coach_name);
            coach_info = (TextView) itemView.findViewById(R.id.coach_info);
            coach_pic = (ImageView) itemView.findViewById(R.id.coach_pic);
            coach_container = (LinearLayout) itemView.findViewById(R.id.coach_container);

        }
    }
}
